package com.wn.web;

import com.github.pagehelper.PageInfo;
import com.wn.common.pojo.PageParam;
import com.wn.common.pojo.Rsp;
import com.wn.common.pojo.Scheme;
import com.wn.service.SchemeService;
import io.swagger.annotations.Api;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestControllerAdvice
@RequestMapping("scheme")
@Api(value = "方案表的接口")
@Slf4j
public class SchemeController {

    @Autowired
    private SchemeService schemeService;

    /**
     * 方案表的分页查询
     * @param
     * @param
     * @return
     */
    @PostMapping("getSchemeList")
    public Rsp getSchemeList(@RequestBody PageParam<Scheme> schemePageParam){
        //分页查询方案
        PageInfo<Scheme> schemeList = schemeService.getSchemeList(schemePageParam);
        return new Rsp().success(schemeList);
    }

    /**
     * 方案添加
     * @return
     */
    @PostMapping("insertScheme")
    public Rsp insertScheme(@RequestBody @Valid Scheme scheme){
        return schemeService.insertScheme(scheme);
    }


    /**
     * 更新
     * @return
     */
    @PostMapping("updataScheme")
    public Rsp updataScheme(@RequestBody @Valid Scheme scheme){
        return schemeService.updataScheme(scheme);
    }

    /**
     * 根据id删除一条数据
     * @param
     * @return
     */
    @PostMapping("deleteSchemeById")
    public Rsp deleteSchemeById(@RequestBody Scheme scheme){
        return schemeService.deleteSchemeById(scheme);

    }

    /**
     * 修改方案状态
     * @param
     * @return
     */
    @PostMapping("updateSchemeStatus")
    public Rsp updateSchemeStatus( @RequestBody Scheme scheme){


        return schemeService.updateSchemeStatus(scheme);
    }

    @PostMapping("getAllScheme")
    public Rsp getAllScheme(){
        System.out.println("过来风");
        Rsp schemeListN = schemeService.getAllScheme();
        return schemeListN;
    }

    @PostMapping("getSchemeItemByid")
    public Rsp getSchemeItemByid(@RequestBody Scheme scheme){
        log.info("id{}",scheme.getId());
       Rsp schemeItemByid = schemeService.getSchemeItemByid(scheme.getId());
        return schemeItemByid;
    }
}
